package com.sanmubird.mywebframework.indicator.domain.executor;

import com.alibaba.fastjson.JSONObject;
import com.sanmubird.mywebframework.indicator.domain.model.Indicator;
import com.sanmubird.mywebframework.indicator.domain.model.IndicatorExecutor;
import com.sanmubird.mywebframework.indicator.domain.model.IndicatorType;

import java.util.Map;
import java.util.Objects;

/**
 * @author sam
 */
public class IndicatorExecutorProvider {

    private final Map<IndicatorType, IndicatorExecutor> executorMap;
    private final IndicatorExecutor empty = new EmptyIndicatorExecutor();

    public IndicatorExecutorProvider(Map<IndicatorType, IndicatorExecutor> executorMap) {
        this.executorMap = executorMap;
    }

    public IndicatorExecutor acquire(IndicatorType indicatortype) {
        Objects.requireNonNull(indicatortype);
        return executorMap.getOrDefault(indicatortype, empty);
    }

    private static class EmptyIndicatorExecutor implements IndicatorExecutor {
        @Override
        public Object execute(Indicator indicator, JSONObject queryParams) {
            return null;
        }
    }

}
